
//
//  ByCellOrderMarket.m
//  mijifen_ios
//
//  Created by mc on 2017/11/1.
//  Copyright © 2017年 itboye. All rights reserved.
//

#import "ByCellOrderMarket.h"

@implementation ByCellOrderMarket
{
    UIView   *_bgView1;
    UIView   *_bgView2;
    UILabel  *_infoLabel;
    UILabel  *_timeLabel;
    UIView   *_linView;
    UILabel  *_statusLabel;
    UIButton *_statusButton;
    
}

+ (instancetype)cellWithTableView:(UITableView*)tableView{
    
    static NSString *cellIdentifier = @"ByCellOrderMarket";
    ByCellOrderMarket *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSeparatorStyleNone;
        self.backgroundColor = [UIColor clearColor];
        [self createViews];
    }
    return self;
}

- (void)createViews{
    _bgView1 = [[UIView alloc] init];
    _bgView1.backgroundColor = [UIColor whiteColor];
    [self addSubview:_bgView1];
    _bgView1.layer.borderWidth = 15;
    _bgView1.layer.cornerRadius = 10.0;
    
    
    _bgView2 = [[UIView alloc] init];
    [self addSubview:_bgView2];
    _bgView2.layer.borderColor = BY_TEXT_COLOR.CGColor;
    _bgView2.layer.borderWidth = 5;
    _bgView2.layer.cornerRadius = 10.0;
    
    _infoLabel = [[UILabel alloc] init];
    [_bgView2 addSubview:_infoLabel];
    
    _timeLabel = [[UILabel alloc] init];
    _timeLabel.textAlignment = NSTextAlignmentRight;
    [_bgView2 addSubview:_timeLabel];
    
    _linView = [[UIView alloc] init];
    [_bgView2 addSubview:_linView];
    _linView.backgroundColor = [UIColor lightGrayColor];
    
    _statusLabel = [[UILabel alloc] init];
    [_bgView2 addSubview:_statusLabel];
    
    _statusButton = [[UIButton alloc] init];
    [_bgView2 addSubview:_statusButton];
    _statusButton.layer.cornerRadius = 30 / 2;
    
}

- (void)setModel:(ByModelOrderMarket *)model{
    _model = model;
    
    // 背景视图1
    [_bgView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(10);
        make.top.equalTo(self.mas_top);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH - 20, 140));
    }];
    
    // 背景视图2
    [_bgView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_bgView1.mas_left).offset(5);
        make.top.equalTo(_bgView1.mas_top).offset(5);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH - 15 * 2, 140 - 10));
    }];
    
    // 信息
    [_infoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_bgView2.mas_left).offset(15);
        make.top.equalTo(_bgView2.mas_top).offset(15);
        make.height.mas_equalTo(@(30));
        make.right.equalTo(_bgView2.mas_right).offset(-15);
    }];
    
    // 时间
    [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(_bgView2.mas_right).offset(-15);
        make.left.equalTo(_bgView2.mas_left).offset(15);
        make.top.equalTo(_infoLabel.mas_bottom).offset(10);
        make.height.mas_equalTo(@(20));
    }];
    
    // 线
    [_linView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_bgView2.mas_left).offset(10);
        make.top.equalTo(_timeLabel.mas_bottom).offset(5);
        make.right.equalTo(_bgView2.mas_right).offset(-10);
        make.height.mas_equalTo(@(1));
    }];
    [CALayer drawDashLine:_linView lineLength:5 lineSpacing:5 lineColor:[UIColor lightGrayColor]];

    
    // 状态button
    NSString *buttonStr;
    if (_model.price.length != 0 && _model.price != nil) {
        buttonStr = [NSString stringWithFormat:@"报价：%@",_model.price];
        [_statusButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [_statusButton setBackgroundColor:[UIColor colorWithWhite:0.90 alpha:1]];
     
    }else{
        buttonStr = @"报名";
        [_statusButton setTitleColor:BY_TEXT_COLOR forState:UIControlStateNormal];
        [_statusButton setBackgroundColor:BY_THEME_COLOR];
    }
    [_statusButton setTitle:buttonStr forState:UIControlStateNormal];

    CGFloat width = [buttonStr getSizeOfString:16].width + 30;
    [_statusButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(_bgView2.mas_right).offset(-15);
        make.top.equalTo(_linView.mas_bottom).offset(5);
        make.size.mas_equalTo(CGSizeMake(width, 30));
    }];
    
    // 状态
    [_statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_infoLabel.mas_left);
        make.top.equalTo(_linView.mas_bottom).offset(5);
        make.bottom.equalTo(_bgView2.mas_bottom).offset(-10);
        make.right.equalTo(_statusButton.mas_left).offset(-10);
    }];
    
    // 我的测试数据
    _infoLabel.text = _model.info;
    _timeLabel.text = _model.create_time;

    
    
}



@end
